package com.server.server_a10.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.server.server_a10.entity.Garden.Garden;
import com.server.server_a10.management.entity.EquipmentInf;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

@Mapper
public interface GardenMapper extends BaseMapper<Garden> {

    @SelectProvider(type = ProviderGarden.class, method = "getGardenInfByRoomId")
    List<Garden> getGardenInfByRoomId(int room_id);

    @SelectProvider(type = ProviderGarden.class, method = "getGardenLimit")
    List<EquipmentInf> getGardenLimit(String name, String room_id, String home_id, int index, int limit);

    @SelectProvider(type = ProviderGarden.class, method = "getGardenLimitCount")
    int getGardenLimitCount(String name,String room_id,String home_id);

    class ProviderGarden {
        public static String getGardenInfByRoomId(int room_id) {
            return "select * from garden where room_id=#{room_id}";
        }

        public static String getGardenLimit(){
            return "select g.id as id,g.name as name,g.room_id as room_id,h.id as home_id,u.id as user_id,u.name as user_name\n" +
                    "from garden g\n" +
                    "    left join room r on r.id = g.room_id\n" +
                    "    left join home h on h.id = r.home_id\n" +
                    "    left join user u on u.id = h.master_id\n" +
                    "where g.id like concat('%',#{name},'%') and  g.room_id like concat('%',#{room_id},'%') and r.home_id like concat('%',#{home_id},'%')\n" +
                    "limit #{index},#{limit}";
        }

        public static String getGardenLimitCount(){
            return "\n" +
                    "select count(*)\n" +
                    "from garden g\n" +
                    "         left join room r on r.id = g.room_id\n" +
                    "         left join home h on h.id = r.home_id\n" +
                    "         left join user u on u.id = h.master_id\n" +
                    "where g.id like concat('%',#{name},'%') and  g.room_id like concat('%',#{room_id},'%') and r.home_id like concat('%',#{home_id},'%')\n";
        }
    }
}
